home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb34.arc
/
MSTACK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-04-06
|
3KB
|
83 lines
{
demonstrates how to move Turbo's stack segment down at
run time. Compile your program with $A000 paragraphs
of maximum heap, then call the procedure LOWERSTACK from the
main block before doing any heap storage operations.
Adjust the constant PARASTORESERVE in LOWERSTACK to free up
any number of paragraphs above Turbo. PARASTORESERVE=1300
(decimal) is enough to guarantee that COMMAND.COM will not
be reloaded after execution finishes. Larger values of
PARASTORESERVE may be desirable if the Turbo program is
using the DOS EXEC function to start up additional processes
or command processors during execution.
Written 10/12/85. Kim Kokkonen, TurboPower Software.
(408)378-3672. Compuserve 72457,2131.
}
PROGRAM mstack;
{-demonstrate moving Turbo's stack down to leave free paragraphs above}
PROCEDURE lowerstack;
{-free up some memory above Turbo}
TYPE
registers = RECORD
CASE Integer OF
1 : (ax, bx, cx, dx, bp, si, di, ds, es, flags : Integer);
2 : (al, ah, bl, bh, cl, ch, dl, dh : Byte);
END;
CONST
{set the following to whatever you want}
parastoreserve = 4096; {64K bytes in this case}
{the procedure initializes the value of the rest}
retadd : Integer = 0; {return address temporarily goes here}
newstackseg : Integer = 0;
parastokeep : Integer = 0;
reg : registers =
(ax : 0; bx : 0; cx : 0; dx : 0; bp : 0;
si : 0; di : 0; ds : 0; es : 0; flags : 0);
BEGIN
{get number of available paragraphs}
reg.ah := $4A;
reg.es := CSeg;
reg.bx := $A000;
MsDos(reg);
{calculate new segment boundaries}
parastokeep := reg.bx-parastoreserve;
newstackseg := SSeg-parastoreserve;
{move stack down}
INLINE(
$8B/$46/$02/ {MOV AX,[BP+02] - gets procedure return address}
$2E/$A3/retadd/ {MOV cs:retadd,AX}
$2E/$8E/$16/newstackseg/ {MOV SS,cs:newstackseg}
$2E/$A1/retadd/ {MOV AX,cs:retadd}
$89/$46/$02/ {MOV [BP+02],AX}
$8B/$C5/ {MOV AX,BP}
$89/$46/$00/ {MOV [BP+00],AX}
$8B/$E5/ {MOV SP,BP}
$55 {PUSH BP}
);
{shrink allocated memory}
reg.ah := $4A;
reg.es := CSeg;
reg.bx := parastokeep;
MsDos(reg);
END; {lowerstack}
FUNCTION cardinal(i : Integer) : Real;
{-return an unsigned 16 bit integer}
VAR
r : Real;
BEGIN
r := i;
IF r < 0.0 THEN r := r+65536.0;
cardinal := r;
END; {cardinal}
BEGIN
WriteLn('SSEG:',cardinal(SSeg):0:0, ' MEMAVAIL:', cardinal(MemAvail):0:0);
lowerstack;
WriteLn('SSEG:',cardinal(SSeg):0:0, ' MEMAVAIL:', cardinal(MemAvail):0:0);
END.